<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"   class="project" >
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="150px">
      <el-collapse v-model="activeNames" @change="handleChange" accordion style="line-height: 48px;">
        <el-collapse-item title="财务信息" name="1">
      <el-form-item label="项目进展" prop="projectJz">
        <el-input v-model="dataForm.projectJz" placeholder="项目进展"></el-input>
      </el-form-item>
      <el-form-item label="签约抬头" prop="projectTt">
        <el-input v-model="dataForm.projectTt" placeholder="签约抬头"></el-input>
      </el-form-item>
      <el-form-item label="立项单编号" prop="projectBh">
        <el-input v-model="dataForm.projectBh" placeholder="立项单编号"></el-input>
      </el-form-item>
      <el-form-item label="合同统计" prop="projectTj">
        <el-input v-model="dataForm.projectTj" placeholder="合同统计"></el-input>
      </el-form-item>
      <el-form-item label="快递" prop="projectExpress">
        <el-input v-model="dataForm.projectExpress" placeholder="快递"></el-input>
      </el-form-item>
      <el-form-item label="回递" prop="projectBackExpress">
        <el-input v-model="dataForm.projectBackExpress" placeholder="回递"></el-input>
      </el-form-item>
      <el-form-item label="发票号" prop="projectFph">
        <el-input v-model="dataForm.projectFph" placeholder="发票号"></el-input>
      </el-form-item>
        </el-collapse-item>
        <el-collapse-item title="项目信息" name="2">
      <el-form-item label="客户名称" prop="projectKhmc">
        <el-input v-model="dataForm.projectKhmc" placeholder="客户名称"></el-input>
      </el-form-item>
      <el-form-item label="项目名称" prop="projectXmmc">
        <el-input v-model="dataForm.projectXmmc" placeholder="项目名称"></el-input>
      </el-form-item>
      <el-form-item label="行业" prop="projectHy">
        <el-input v-model="dataForm.projectHy" placeholder="行业"></el-input>
      </el-form-item>
      <el-form-item label="启动日期" prop="projectQdrq">
        <el-input v-model="dataForm.projectQdrq" placeholder="启动日期"></el-input>
      </el-form-item>
      <el-form-item label="结束日期" prop="projectJsrq">
        <el-input v-model="dataForm.projectJsrq" placeholder="结束日期"></el-input>
      </el-form-item>
      <el-form-item label="回款日期" prop="projectHkrq">
        <el-input v-model="dataForm.projectHkrq" placeholder="回款日期"></el-input>
      </el-form-item>
      <el-form-item label="合同金额" prop="projectHtje">
        <el-input v-model="dataForm.projectHtje" placeholder="合同金额"></el-input>
      </el-form-item>
      <el-form-item label="结算金额" prop="projectJsje">
        <el-input v-model="dataForm.projectJsje" placeholder="结算金额"></el-input>
      </el-form-item>
      <el-form-item label="是否回款" prop="projectSfhk">
        <el-input v-model="dataForm.projectSfhk" placeholder="是否回款"></el-input>
      </el-form-item>
      <el-form-item label="已回款金额" prop="projectYhkje">
        <el-input v-model="dataForm.projectYhkje" placeholder="已回款金额"></el-input>
      </el-form-item>
      <el-form-item label="未回款金额" prop="projectWhkje">
        <el-input v-model="dataForm.projectWhkje" placeholder="未回款金额"></el-input>
      </el-form-item>
      <el-form-item label="负责人" prop="projectFzr">
        <el-input v-model="dataForm.projectFzr" placeholder="负责人"></el-input>
      </el-form-item>
      <el-form-item label="客户决策人" prop="projectKhjcr">
        <el-input v-model="dataForm.projectKhjcr" placeholder="客户决策人"></el-input>
      </el-form-item>
      <el-form-item label="客户负责人" prop="projectKhfzr">
        <el-input v-model="dataForm.projectKhfzr" placeholder="客户负责人"></el-input>
      </el-form-item>
      <el-form-item label="客户接口人" prop="projectKhjkr">
        <el-input v-model="dataForm.projectKhjkr" placeholder="客户接口人"></el-input>
      </el-form-item>
        </el-collapse-item>
        <el-collapse-item title="盈利信息" name="3">
      <el-form-item label="预付金额" prop="projectYfje">
        <el-input v-model="dataForm.projectYfje" placeholder="预付金额"></el-input>
      </el-form-item>
      <el-form-item label="媒介成本" prop="projectMjcb">
        <el-input v-model="dataForm.projectMjcb" placeholder="媒介成本"></el-input>
      </el-form-item>
      <el-form-item label="实际成本" prop="projectSjcb">
        <el-input v-model="dataForm.projectSjcb" placeholder="实际成本"></el-input>
      </el-form-item>
      <el-form-item label="其它成本" prop="projectQtcb">
        <el-input v-model="dataForm.projectQtcb" placeholder="其它成本"></el-input>
      </el-form-item>
      <el-form-item label="预估利润率" prop="projectYglrl">
        <el-input v-model="dataForm.projectYglrl" placeholder="预估利润率"></el-input>
      </el-form-item>
      <el-form-item label="实际利润率" prop="projectSjlrl">
        <el-input v-model="dataForm.projectSjlrl" placeholder="实际利润率"></el-input>
      </el-form-item>
      <el-form-item label="回款周期" prop="projectHkzq">
        <el-input v-model="dataForm.projectHkzq" placeholder="回款周期"></el-input>
      </el-form-item>
        </el-collapse-item>
        <el-collapse-item title="联盟信息" name="4">
      <el-form-item label="联盟人" prop="projectLmr">
        <el-input v-model="dataForm.projectLmr" placeholder="联盟人"></el-input>
      </el-form-item>
        </el-collapse-item>
      </el-collapse>
        <div style="margin-top: 20px">
      <el-form-item label="备注" prop="projectRemark">
        <el-input type="textarea" v-model="dataForm.projectRemark" placeholder="备注"></el-input>
      </el-form-item>
        </div>
    </el-form>
    <div style="margin-top: 20px">
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </div>
  </el-dialog>
</template>

<style>
  .project [class*=" el-icon-"], [class^=el-icon-] {
    line-height: 48px;
  }
</style>

<script>
  import API from '@/api'
  export default {
    data () {
      return {
        visible: false,
        activeNames: ['1'],
        dataForm: {
          id: 0,
          userId: '',
          projectJz: '',
          projectTt: '',
          projectBh: '',
          projectTj: '',
          projectExpress: '',
          projectBackExpress: '',
          projectFph: '',
          projectKhmc: '',
          projectXmmc: '',
          projectHy: '',
          projectQdrq: '',
          projectJsrq: '',
          projectHkrq: '',
          projectHtje: '',
          projectJsje: '',
          projectSfhk: '',
          projectYhkje: '',
          projectWhkje: '',
          projectFzr: '',
          projectKhjcr: '',
          projectKhfzr: '',
          projectKhjkr: '',
          projectYfje: '',
          projectMjcb: '',
          projectSjcb: '',
          projectQtcb: '',
          projectYglrl: '',
          projectSjlrl: '',
          projectHkzq: '',
          projectLmr: '',
          projectRemark: '',
          createUserId: '',
          createTime: ''
        },
        dataRule: {
          projectJz: [
            { required: true, message: '项目进展不能为空', trigger: 'blur' }
          ],
          projectTt: [
            { required: true, message: '签约抬头不能为空', trigger: 'blur' }
          ],
          projectKhmc: [
            { required: true, message: '客户名称不能为空', trigger: 'blur' }
          ],
          projectXmmc: [
            { required: true, message: '项目名称不能为空', trigger: 'blur' }
          ],
          projectHy: [
            { required: true, message: '行业不能为空', trigger: 'blur' }
          ],
          projectLmr: [
            { required: true, message: '联盟人不能为空', trigger: 'blur' }
          ],
          projectRemark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            API.baseproject.info(this.dataForm.id).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.baseproject.userId
                this.dataForm.projectJz = data.baseproject.projectJz
                this.dataForm.projectTt = data.baseproject.projectTt
                this.dataForm.projectBh = data.baseproject.projectBh
                this.dataForm.projectTj = data.baseproject.projectTj
                this.dataForm.projectExpress = data.baseproject.projectExpress
                this.dataForm.projectBackExpress = data.baseproject.projectBackExpress
                this.dataForm.projectFph = data.baseproject.projectFph
                this.dataForm.projectKhmc = data.baseproject.projectKhmc
                this.dataForm.projectXmmc = data.baseproject.projectXmmc
                this.dataForm.projectHy = data.baseproject.projectHy
                this.dataForm.projectQdrq = data.baseproject.projectQdrq
                this.dataForm.projectJsrq = data.baseproject.projectJsrq
                this.dataForm.projectHkrq = data.baseproject.projectHkrq
                this.dataForm.projectHtje = data.baseproject.projectHtje
                this.dataForm.projectJsje = data.baseproject.projectJsje
                this.dataForm.projectSfhk = data.baseproject.projectSfhk
                this.dataForm.projectYhkje = data.baseproject.projectYhkje
                this.dataForm.projectWhkje = data.baseproject.projectWhkje
                this.dataForm.projectFzr = data.baseproject.projectFzr
                this.dataForm.projectKhjcr = data.baseproject.projectKhjcr
                this.dataForm.projectKhfzr = data.baseproject.projectKhfzr
                this.dataForm.projectKhjkr = data.baseproject.projectKhjkr
                this.dataForm.projectYfje = data.baseproject.projectYfje
                this.dataForm.projectMjcb = data.baseproject.projectMjcb
                this.dataForm.projectSjcb = data.baseproject.projectSjcb
                this.dataForm.projectQtcb = data.baseproject.projectQtcb
                this.dataForm.projectYglrl = data.baseproject.projectYglrl
                this.dataForm.projectSjlrl = data.baseproject.projectSjlrl
                this.dataForm.projectHkzq = data.baseproject.projectHkzq
                this.dataForm.projectLmr = data.baseproject.projectLmr
                this.dataForm.projectRemark = data.baseproject.projectRemark
                this.dataForm.createUserId = data.baseproject.createUserId
                this.dataForm.createTime = data.baseproject.createTime
              }
            })
          }
        })
      },
      handleChange (val) {
        console.log(val)
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            var params = {
              'id': this.dataForm.id || undefined,
              'userId': this.dataForm.userId,
              'projectJz': this.dataForm.projectJz,
              'projectTt': this.dataForm.projectTt,
              'projectBh': this.dataForm.projectBh,
              'projectTj': this.dataForm.projectTj,
              'projectExpress': this.dataForm.projectExpress,
              'projectBackExpress': this.dataForm.projectBackExpress,
              'projectFph': this.dataForm.projectFph,
              'projectKhmc': this.dataForm.projectKhmc,
              'projectXmmc': this.dataForm.projectXmmc,
              'projectHy': this.dataForm.projectHy,
              'projectQdrq': this.dataForm.projectQdrq,
              'projectJsrq': this.dataForm.projectJsrq,
              'projectHkrq': this.dataForm.projectHkrq,
              'projectHtje': this.dataForm.projectHtje,
              'projectJsje': this.dataForm.projectJsje,
              'projectSfhk': this.dataForm.projectSfhk,
              'projectYhkje': this.dataForm.projectYhkje,
              'projectWhkje': this.dataForm.projectWhkje,
              'projectFzr': this.dataForm.projectFzr,
              'projectKhjcr': this.dataForm.projectKhjcr,
              'projectKhfzr': this.dataForm.projectKhfzr,
              'projectKhjkr': this.dataForm.projectKhjkr,
              'projectYfje': this.dataForm.projectYfje,
              'projectMjcb': this.dataForm.projectMjcb,
              'projectSjcb': this.dataForm.projectSjcb,
              'projectQtcb': this.dataForm.projectQtcb,
              'projectYglrl': this.dataForm.projectYglrl,
              'projectSjlrl': this.dataForm.projectSjlrl,
              'projectHkzq': this.dataForm.projectHkzq,
              'projectLmr': this.dataForm.projectLmr,
              'projectRemark': this.dataForm.projectRemark,
              'createUserId': this.dataForm.createUserId,
              'createTime': this.dataForm.createTime
            }
            var tick = !this.dataForm.id ? API.baseproject.add(params) : API.baseproject.update(params)
            tick.then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
